package cn.edu.suse.epilepsy.service.impl;

import cn.edu.suse.epilepsy.entity.pojo.DoctorManage;
import cn.edu.suse.epilepsy.entity.pojo.Patient;
import cn.edu.suse.epilepsy.entity.vo.DoctorMannageVo;
import cn.edu.suse.epilepsy.entity.vo.PatientVo;
import cn.edu.suse.epilepsy.mapper.PatientMapper;
import cn.edu.suse.epilepsy.service.PatientService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Author: QingShu
 * @Date: 2024/7/10 23:12
 */
@Service
@Transactional(rollbackFor = Throwable.class)
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements PatientService {

    @Autowired
    private PatientMapper patientMapper;

    @Override
    public List<PatientVo> selectAllPatient() {
        List<Patient> patients = patientMapper.selectList(null);
        List<PatientVo> patientVos = new ArrayList<>();

        for (Patient patient : patients) {
            PatientVo patientVo = new PatientVo();
            BeanUtils.copyProperties(patient, patientVo);
            patientVos.add(patientVo);
        }
        return patientVos;
    }

    @Override
    public int updatePatient(Patient patient) {
        int i = patientMapper.updateById(patient);
        return i;
    }

    @Override
    public Patient addPatient(Patient dto) {
        patientMapper.insert(dto);
        return dto;
    }
}
